package com.itheima.controller.backend.security;

import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.common.entity.Result;
import com.itheima.common.entity.Result2;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.dto.CheckGroupDto;
import com.itheima.pojo.vo.CheckGroupVo;
import com.itheima.service.CheckgroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 检查组组增删改查接口
 */
@RestController
@Slf4j
@RequestMapping("/checkgroup")
public class CheckgroupController {
    @Autowired
    private CheckgroupService checkgroupService;
    /**
     * 添加检查组
     * @param group
     * @param checkItemIds
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody CheckGroupDto group, String checkItemIds){
        log.info("添加检查组：{}",group);
        log.info("添加检查项：{}",checkItemIds);
        checkgroupService.add(group,checkItemIds);
        return Result.success();
    }
    /**
     * 删除检查组
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public Result delete(Integer id){
        log.info("删除检查组：{}",id);
        checkgroupService.deleteById(id);
        return Result.success();
    }
    /**
     * 修改检查组
     * @param group
     * @param checkItemIds
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody CheckGroupDto group, String checkItemIds){
        log.info("修改检查组：{}",group);
        log.info("修改检查项：{}",checkItemIds);
        checkgroupService.update(group,checkItemIds);
        return Result.success();
    }
    /**
     * 分页查询检查组
     * @return
     */
    @PostMapping("/findPage")
    public Result<PageResult> findPage(@RequestBody QueryPageBean queryPageBean) {
        log.info("分页查询检查组：{}", queryPageBean);
        PageResult pageResult = checkgroupService.findPage(queryPageBean);
        return Result.success(pageResult);
    }
    /**
     * 查询所有检查组
     * @return
     */
    @GetMapping("/findAll")
    public Result2 findAll() {
        log.info("查询所有检查组");
        List<CheckGroupVo> list = checkgroupService.findAll();
        return new Result2(true, "查询成功", list);
    }
    /**
     * 根据检查组id查询检查项
     * @param id
     * @return
     */
    @GetMapping("/getById")
    public Result<CheckGroupVo> getById(Integer id) {
        log.info("根据检查组id查询检查项：{}", id);
        CheckGroupVo checkGroupVo = checkgroupService.getById(id);
        return Result.success(checkGroupVo);
    }

}
